// lib/utils/font.dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class AppFonts {
  // 使用 ScreenUtil 的 sp 单位进行字体适配（推荐）
  static double fontSize10 = 10.sp;
  static double fontSize12 = 12.sp;
  static double fontSize14 = 14.sp;
  static double fontSize16 = 16.sp;
  static double fontSize18 = 18.sp;
  static double fontSize20 = 20.sp;
  static double fontSize24 = 24.sp;
  static double fontSize28 = 28.sp;
  static double fontSize32 = 32.sp;
  static double fontSize36 = 36.sp;

  // 原有的字体粗细常量保持不变
  static const FontWeight fontWeight400 = FontWeight.w400;
  static const FontWeight fontWeight500 = FontWeight.w500;
  static const FontWeight fontWeight600 = FontWeight.w600;
  static const FontWeight fontWeight700 = FontWeight.w700;
  static const FontWeight fontWeight800 = FontWeight.w800;
  static const FontWeight fontWeight900 = FontWeight.w900;

  // 新增：根据屏幕尺寸适配字体大小的方法，以375为基准（保留供手动调用）
  static double adaptiveFontSize(double fontSize, BuildContext context) {
    final screenWidth = MediaQuery.of(context).size.width;
    final scale = screenWidth / 375.0;
    return fontSize * scale;
  }

  // 新增：使用 flutter_screenutil 的适配方法（推荐）
  static double adaptiveFontSizeByScreenUtil(double fontSize) {
    return fontSize.sp;
  }

  // 新增：获取适配后的文本样式
  static TextStyle adaptiveTextStyle({
    double? fontSize,
    FontWeight? fontWeight,
    Color? color,
    double? letterSpacing,
    TextDecoration? decoration,
    BuildContext? context,
  }) {
    return TextStyle(
      fontSize: fontSize != null
          ? (context != null
                ? adaptiveFontSize(fontSize, context)
                : adaptiveFontSizeByScreenUtil(fontSize))
          : null,
      fontWeight: fontWeight,
      color: color,
      letterSpacing: letterSpacing,
      decoration: decoration,
    );
  }
}
